package ssx.demo.springbootmysqlcurd.config;

import com.github.pagehelper.PageInterceptor;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 *
 */
@Component
public class MybatisConf {

//    @Autowired
//    private SqlSessionTemplate sqlSessionTemplate;

    //use this1
    public MybatisConf(SqlSessionTemplate sqlSessionTemplate) {
        System.out.println("this is method param:"+sqlSessionTemplate);
        f(sqlSessionTemplate);
    }

    private void f(SqlSessionTemplate sqlSessionTemplate){
        //pageHelper分页配置（只参考这部分配置就可以了）
        PageInterceptor pageInterceptor = new PageInterceptor();

        Properties properties=new Properties();
        //下面这行代码可以不配置，因为在源码中会默认给properties进行如下配置
          properties.put("dialect", "com.github.pagehelper.PageHelper");
        pageInterceptor.setProperties(properties);
        sqlSessionTemplate.getSqlSessionFactory().getConfiguration()
                .addInterceptor(pageInterceptor);
    }

    //use this 2
//    @Bean
    public PageInterceptor beanfun(){
        return new PageInterceptor();
    }

}
